package com.java.module.quartz.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.domain.page.TableDataInfo;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.common.utils.poi.ExcelUtil;
import com.java.module.quartz.domain.CronJobLog;
import com.java.module.quartz.service.ICronJobLogService;

/**
 * 调度日志操作处理
 * 
 * @author Administrator
 */
@RestController
@RequestMapping("/quartz/cronJobLog")
public class CronJobLogController {

    @Autowired
    private ICronJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @PreAuthorize("@ss.hasPermi('quartz:cronJobLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CronJobLog cronJobLog) {
        WebKit.startPage();
        List<CronJobLog> list = jobLogService.selectJobLogList(cronJobLog);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出定时任务调度日志列表
     */
    @PreAuthorize("@ss.hasPermi('quartz:cronJobLog:export')")
    @Log(title = "任务调度日志", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CronJobLog cronJobLog) {
        List<CronJobLog> list = jobLogService.selectJobLogList(cronJobLog);
        ExcelUtil<CronJobLog> util = new ExcelUtil<CronJobLog>(CronJobLog.class);
        return util.exportExcel(list, "调度日志");
    }

    /**
     * 根据调度编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('quartz:cronJobLog:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable Long jobLogId) {
        return AjaxResult.success(jobLogService.selectJobLogById(jobLogId));
    }

    /**
     * 删除定时任务调度日志
     */
    @PreAuthorize("@ss.hasPermi('quartz:cronJobLog:remove')")
    @Log(title = "定时任务调度日志", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{jobLogIds}")
    public AjaxResult remove(@PathVariable Long[] jobLogIds) {
        return WebKit.toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
    }

    /**
     * 清空定时任务调度日志
     */
    @PreAuthorize("@ss.hasPermi('quartz:cronJobLog:remove')")
    @Log(title = "调度日志", businessType = BusinessTypeEnum.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        jobLogService.cleanJobLog();
        return AjaxResult.success();
    }

}